﻿/**
 * Created by caelan on 2018/10/22.
 */


/*创建业务面板参数*/
function createElementObj(){
  return {
    requestFlag:"",
    nameArray:[],
    isGroupByDay:false,
    hasCalWays:false,
    calWayArray:[],
    requestTypeArray:[],
    spatialWayArray:[],
    stationTypeArray:[],
    isNccYearSetting:false,
    timeTypeArray:[],
    zhibiaoArray:[],
    zhibiaoCaptionArray:[],
    thresholdRange: {},         //阈值范围
    historyStatic: [],          //历史统计
    spaceType: [],        //空间类型
    isDayTimeTypeSupportted:false,
    indexSetting: [],      /*指标设置*/
    isNotTable:false,       /*针对格点数据等没有表格的*/
    dapServerName:"",		 /*针对格点数据等没有表格的对应dapServer标识*/
    yaosuQueryRequestAnalysisType:"Spatial",   //模拟bean类型 YaosuRequest or HistorySamePeriodRequest
    historyCalWays:null,
    panelNames : {}, //自定义面板名称
    Droughs:[],
    drySetting: [],     /*干热风指标设置*/
 HumidityAvgs:[], //土壤湿度层次平均
 HumidityTypes:[],//土壤湿度类型
CropTypes:[]//作物类型

  };
}
/*初始化业务面板*/
function clearElementObj(){
  elementObj={
    requestFlag:"",
    nameArray:[],
    isGroupByDay:true,
    hasCalWays:false,
    calWayArray:[],
    requestTypeArray:[],
    spatialWayArray:[],
    stationTypeArray:[],
    isNccYearSetting:false,
    timeTypeArray:[],
    zhibiaoArray:[],
    zhibiaoCaptionArray:[],
    thresholdRange: {},
    historyStatic: [],
    spaceType: [],
    indexSetting: [],      /*指标设置*/
    isNotTable:false,       /*针对格点数据等没有表格的*/
    dapServerName:"",		 /*针对格点数据等没有表格的对应dapServer标识*/
    yaosuQueryRequestAnalysisType:"Spatial",   //模拟bean类型 YaosuRequest or HistorySamePeriodRequest
    historyCalWays:null,
    panelNames : {}, //自定义面板名称
    drySetting: [],      /*干热风指标设置*/
      HumidityAvgs:[], //土壤湿度层次平均
      HumidityTypes:[],//土壤湿度类型
      CropTypes:[],//作物类型
      Droughs:[],
  };
}

/*创建请求参数模版*/
function CreateRequestData () {
  return {
    "startTime": 20180101,
    "endTime": 20181022,
    "businessTimeType": "DayTimeType",
    "requestFlag": "PingGu_Disaster_HighTemp_DayTemp_MinTemp_History",
    "taskID": "",
    "topicName": "10.96.91.2025afeadca-9bf9-46c1-ab33-16d7ad811b40",
    "expositionInfo": {"formName": "单日气温", "formBusinessName": "单日气温(日最低)", "labelFields": [], "columnFilltype": 0},
    "gISParamInfo": {
      "formName": "单日气温",
      "formBusinessName": "单日气温(日最低)",
      "labelFields": [],
      "keyName": "单日气温",
      "linkField": "",
      "renderField": "日最低气温",
      "renderPath": "",
      "templateName": "",
      "renderType": "IsoRegionTheme",
      "themeType": "Range",
      "interpolationParam": {},
      "neighbourParam": {},
      "lineSmoothness": 0,
      "mainTitle": "",
      "subTitleAppendix": "",
      "legendUnit": "",
      "orgnization": "",
      "isTaiWanVisible": false
    },
    "tableParamInfo": {"formName": "单日气温", "formBusinessName": "单日气温(日最低)", "labelFields": [], "columnFilltype": 0},
    "chartParamInfo": {
      "formName": "单日气温",
      "formBusinessName": "单日气温(日最低)",
      "labelFields": [],
      "templateName": "",
      "isMultipart": false,
      "multipartFieldName": "",
      "xLabel": "",
      "xFieldName": "",
      "xGroupFieldName": "",
      "yFieldNames": [],
      "yLabelNames": [],
      "chartTypes": [],
      "chartYTypes": [],
      "yAxisLabels": []
    },
    "userName": "",
    "requestDateTime": "2018-10-23 15:06:56",
    "canceled": false,
    "showFlag": 1,
    "stopRequestFlag": "9f0569e8-c71a-468b-a2e6-b2c1073a6ae8",
    "tag": "",
    "customCaption": "",
    "predictDays": 0,
    "qibaoDays": 0,
    "paramsMap": "",
    "dayTimeType": "None",
    "hours": 0,
    "standStartYear": 1981,
    "standEndYear": 2010,
    "minYear": 1951,
    "maxYear": 2018,
    "stations": [],
    "regions": [],
    "customTopRegionName": "",
    "staType": "AllStation",
    "staSelectType": "StationSelectAll",
    "customFilter": "",
    "customMainField": "",
    "staFilter": "EncryptionStation",
    "calWay": "NoneCalWay",
    "statisticWays": [],
    "regValueType": "RegionSum",
    "spatialStaticsWay": "SingleStationWay",
    "leftArray": [],
    "rightArray": [],
    "leftOpers": [">="],
    "rightOpers": ["<="],
    "historyCalWays": [],
    "continuousWay": "NoneContinuousCalWay",
    "singleDayLeft": -9999.0,
    "singleDayRight": -9999.0,
    "singleDayLeftOper": "",
    "singleDayRightOper": "",
    "years": []
  }

}



/**
 * 16进制转RGBA
 * @param hex 例如:"#23ff45"
 * @param opacity 透明度
 * @returns {string}
 */
function hexToRgba(hex, opacity) {
  return "RGBA(" + parseInt("0x" + hex.slice(1, 3)) + "," + parseInt("0x" + hex.slice(3, 5)) + "," + parseInt("0x" + hex.slice(5, 7)) + "," + opacity + ")";
}


/*随机颜色*/
function randomColor() {
  return '#'+Math.floor(Math.random()*0xffffff).toString(16);
}




/*补色*/
function complementaryColor (imgUrl, callback) {
  var img = new Image();
  img.src = imgUrl;
  //计算对应的通道值
  //图片加载后进行处理
  img.onload = function () {
    var width = img.width,
      height = img.height,
      canvas = document.createElement('canvas'),
      ctx = canvas.getContext('2d');
    canvas.width = width;
    canvas.height = height;
    // 将源图片复制到画布上
    ctx.drawImage(img, 0, 0, width, height);
    // 获取画布的像素信息
    var imageData = ctx.getImageData(0, 0, width, height);
    var data = imageData.data;
    // 对像素集合中的单个像素进行循环，每个像素是由4个通道组成，所以要注意
    var i = 0;
    while (i < data.length) {
      var r = data[i++],
        g = data[i++],
        b = data[i++],
        a = data[i++];

      data[i - 4] = 255 - r;
      data[i - 3] = 255 - g;
      data[i - 2] = 255 - b;
      data[i - 1] = a; //处理透明的图片和不透明的图片
    }
    // 将修改后的代码复制回画布中
    ctx.putImageData(imageData, 0, 0);
    // 图片导出为 png 格式
    var type = 'png';
    var imgData = canvas.toDataURL(type);
    // console.log(imgData); // 生成base64
    callback && callback(imgData);
  };
}